package com.youlai.quarkus.system.converter;

import com.youlai.quarkus.system.model.entity.SysMenu;
import com.youlai.quarkus.system.model.form.MenuForm;
import com.youlai.quarkus.system.model.vo.MenuVO;
import jakarta.enterprise.context.ApplicationScoped;

/**
 * 菜单对象转换器
 *
 * @author haoxr
 * @since 2022/7/29
 */
@ApplicationScoped
public class MenuConverter {

    public MenuVO entity2Vo(SysMenu entity) {
        if (entity == null) {
            return null;
        } else {
            MenuVO menuVO = new MenuVO();
            menuVO.setId(entity.getId());
            menuVO.setParentId(entity.getParentId());
            menuVO.setName(entity.getName());
            menuVO.setType(entity.getType());
            menuVO.setPath(entity.getPath());
            menuVO.setComponent(entity.getComponent());
            menuVO.setSort(entity.getSort());
            menuVO.setVisible(entity.getVisible());
            menuVO.setIcon(entity.getIcon());
            menuVO.setRedirect(entity.getRedirect());
            menuVO.setPerm(entity.getPerm());
            return menuVO;
        }
    }

    public MenuForm entity2Form(SysMenu entity) {
        if (entity == null) {
            return null;
        } else {
            MenuForm menuForm = new MenuForm();
            menuForm.setId(entity.getId());
            menuForm.setParentId(entity.getParentId());
            menuForm.setName(entity.getName());
            menuForm.setType(entity.getType());
            menuForm.setPath(entity.getPath());
            menuForm.setComponent(entity.getComponent());
            menuForm.setPerm(entity.getPerm());
            menuForm.setVisible(entity.getVisible());
            menuForm.setSort(entity.getSort());
            menuForm.setIcon(entity.getIcon());
            menuForm.setRedirect(entity.getRedirect());
            return menuForm;
        }
    }

    public SysMenu form2Entity(MenuForm menuForm) {
        if (menuForm == null) {
            return null;
        } else {
            SysMenu sysMenu = new SysMenu();
            sysMenu.setId(menuForm.getId());
            sysMenu.setParentId(menuForm.getParentId());
            sysMenu.setName(menuForm.getName());
            sysMenu.setType(menuForm.getType());
            sysMenu.setPath(menuForm.getPath());
            sysMenu.setComponent(menuForm.getComponent());
            sysMenu.setPerm(menuForm.getPerm());
            sysMenu.setVisible(menuForm.getVisible());
            sysMenu.setSort(menuForm.getSort());
            sysMenu.setIcon(menuForm.getIcon());
            sysMenu.setRedirect(menuForm.getRedirect());
            return sysMenu;
        }
    }

}